<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <link href="style/css.css" rel="stylesheet" type="text/css" />
    <link href="style/gysqy.css" rel="stylesheet" type="text/css" />
    <link href="style/product_top.css" rel="stylesheet" type="text/css" />
    <script src="lib/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="lib/json2.js" type="text/javascript"></script>
    <script src="lib/jsmart.js" type="text/javascript"></script>
    <script src="script/app.js" type="text/javascript"></script>
    <script src="script/urledit.js" type="text/javascript"></script>
    <script id="suppliercount" type="text/x-jsmart-tmpl">
	共{$hits.total}条记录
    </script>
    <script id="supplier" type="text/x-jsmart-tmpl">  
	{foreach $hits.hits as $name => $supplier}
		<li>
			<div class="fl gysqy_lb_tp">
				<img src="resources/img/gysqy_pic01.jpg" width="122" height="120" /></div>
			<div class="fl gysqy_lb_nr">
				<div class="gysqy_lb_title">
					<a style="_line-height: 18px;" href="/Manufacturer/Index?mId=8176" title="{$supplier._source.companyname}"
						target="_blank">{$supplier._source.companyname}</a></div>
				<div class="gysqy_lb_wz">
				</div>
				<div class="gysqy_lb_lx" title="类型：销售商  主营产品: 水泵、风机">
					类型：
					{if $supplier._source.doctype == "supplier"}
						供应商
					{/if}
				</div>
				<div class="gysqy_lb_dz">
					地址：{$supplier._source.companyaddress}</div>
			</div>
			<div class="fl gysqy_lb_an">
				<a href="/Manufacturer/Index?mId=8176" title="{$supplier._source.companyname}" target="_blank">
					<img src="resources/img/lxsj.png" width="92" height="28" border="0" /></a>
			</div>
		</li>
	{/foreach}
    </script>
    <script id="supplierpage" type="text/x-jsmart-tmpl">
	<div class="page">
		<div class="pagination">
			{if $pagecount > 1}			
				<a class="pageNum"><b>
				{$currentpage}
				</b>/<b>
				{$pagecount}
				</b></a>	
				{if (1 != $currentpage)}
					<a href="{urlset('pageIndex', 1)}" class="first">首页</a>
					<a href="{urlset('pageIndex', $currentpage-1)}" class="prev">上一页</a>
				{/if}	
				
				{for $i=$start to $end}
					{if ($i == $currentpage)}
						<span class="current">{$i}</span>
					{else}
						<a href="{urlset('pageIndex', $i)}">{$i}</a>
					{/if}
				{/for}
				
				{if ($pagecount != $currentpage)}
					<a href="{urlset('pageIndex', $currentpage+1)}" class="first">下一页</a>
					<a href="{urlset('pageIndex', $pagecount)}" class="last">尾页</a>
				{/if}	
			{/if}
		</div>
	</div>
	</script>
</head>
<body>
    <center>
        <div id="box">
            <div class="left fl">
                <div class="gys">
                    <form>
                    <div class="gys_textbox fl">
                        <input name="" type="text" class="gys_wbk" id="keyM" /></div>
                    <div class="fl">
                        <a href="#" class="btnManufacturerSearch1">
                            <img src="resources/img/cz_an.jpg" width="100" height="33" border="0" /></a></div>
                    </form>
                </div>
                <!-- gysqy_lb -->
                <div class="gysqy">
                    <div class="gysqy_title">
                        <div class="fl gys_name">
                            供应商</div>
                        <div class="fl record" id="count">
                            
                        </div>
                    </div>
                    <div class="gysqy_lb">
                        <ul id="supplierlist">
                        </ul>
                    </div>
                </div>
                
                <div id="page">

                </div>
            </div>
        </div>
        <script type="text/javascript">
        $(document).ready(
			function () {								
				var myurl=new UrlEdit.URL(document.URL);
				var values = new Array();				
				if(myurl.get("pageIndex") != undefined)
					currentpage = myurl.get("pageIndex");
				if(myurl.get("pagesize") != undefined)
					pagesize = myurl.get("pagesize");
				if(myurl.get("searchvalue") != undefined && myurl.get("searchvalue") != "")
				{
					values = myurl.get("searchvalue").split(' ');
				}
					
				var skip = pagesize * (currentpage - 1);
				var pageparam = "?from=" + skip + "&size=" + pagesize;					
				for (ind in values)
				{
					pageparam = pageparam + "&q=companyname:\"" + values[ind] + "\""
				}
			    $.ajax({
			        url: searchpath + '/supplier/_search' + pageparam,
			        type: 'GET',
			        dataType: 'json',
			        success: function (data) {
			            var tpl = new jSmart(document.getElementById('supplier').innerHTML);
			            var res = tpl.fetch(data);
			            $("#supplierlist").html(res);
						
						page = new Array();
						page.currentpage = currentpage;
						page.pagecount = Math.ceil(data.hits.total / pagesize);
						page.start = 1;
						page.end = 9;
						if (page.pagecount > 9)
						{
							if (currentpage > 4)
							{
								if (page.pagecount - currentpage > 4)
								{
									page.start = currentpage - 4;
									page.end = currentpage + 4;
								}
								else
								{
									page.end = page.pagecount;
									page.start = end - 8;
								}
							}
						
						}
						else
						{
							page.end = page.pagecount;
						}
						tpl = new jSmart(document.getElementById('supplierpage').innerHTML);
						res = tpl.fetch(page);
			            $("#page").html(res);			
						
						tpl = new jSmart(document.getElementById('suppliercount').innerHTML);
			            var res = tpl.fetch(data);
			            $("#count").html(res);			
			        }
			    });
				
				$(".btnManufacturerSearch1").live("click", function(){
					var searchvalue = $("#keyM").val();
					searchparams = "?searchvalue=" + searchvalue;
					myurl.remove("pageIndex");
					myurl.remove("pagesize");
					myurl.remove("searchvalue");
					window.location.href = myurl.url() + searchparams;
				});
			}
		);
        </script>
    </center>
</body>
</html>
